package com.mike.uaa.core;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author z
 */
@Getter
public class User implements CredentialsContainer, Serializable {

    private static final long serialVersionUID = 5236617915182892884L;

    /**
     * 用户id
     */
    private Integer id;

    /**
     * 用户账号
     */
    private String username;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 用户凭证
     */
    private String password;

    /**
     * 账号状态
     */
    private Integer status;
    /**
     * 手机号
     */
    private String mobile;

    /**
     * 最后登录时间
     */
    private LocalDateTime lastLogin;

    @Override
    public void eraseCredentials() {
        this.password = null;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private final User user = new User();

        public Builder id(Integer id) {
            user.id = id;
            return this;
        }

        public Builder username(String username) {
            user.username = username;
            return this;
        }

        public Builder nickname(String nickname) {
            user.nickname = nickname;
            return this;
        }

        public Builder password(String password) {
            user.password = password;
            return this;
        }

        public Builder status(Integer status) {
            user.status = status;
            return this;
        }

        public Builder status(String status) {
            this.user.status = StrUtil.isNotEmpty(status) ? Integer.valueOf(status) : null;
            return this;
        }

        public Builder mobile(String mobile) {
            user.mobile = mobile;
            return this;
        }


        public Builder lastLogin(LocalDateTime lastLogin) {
            user.lastLogin = lastLogin;
            return this;
        }

        public User build() {
            return user;
        }
    }
}
